/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rosic.forms;

import com.sun.lwuit.Button;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;

/**
 *
 * @author David
 */
public class RutaMisDestinosForm implements ActionListener{

      /**
     *
     */
    private Form form;
    /**
     *
     */
    private MidletPrincipal principal;

     private Command volver;
     /**
      * combo box con los destinos que el usuario ha guardado por defecto
      */
   private ComboBox cbxDestinos;
   /**
    * boton para mosrar el mapa
    */
   private Button btnVerMapa;

    public RutaMisDestinosForm(MidletPrincipal principal, String[] destinos) {
        this.principal = principal;
      


        form = new Form("Buscar Ruta");
        form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        Label lblDestinos= new Label("Escoja el destino");

        btnVerMapa = new Button("Ver Mapa");
        btnVerMapa.setAlignment(Label.CENTER);
        btnVerMapa.addActionListener(this);

        cbxDestinos = new ComboBox(destinos);
        cbxDestinos.setSelectedIndex(0);

        form.addComponent(lblDestinos);
        form.addComponent(cbxDestinos);
        form.addComponent(btnVerMapa);

         volver = new Command("Volver");
            form.addCommand(volver);
            form.setCommandListener(this);
    }


    public void actionPerformed(ActionEvent e) {
         if (e.getCommand() != null) {
            if (e.getCommand().equals(volver)) {
                principal.showPreviousForm();
            }
        }

            if(e.getSource().equals(btnVerMapa)){


            principal.mostrarRutaSeguraA(form, cbxDestinos.getSelectedItem().toString());
        }
    }

    /**
     * @return the form
     */
    public Form getForm() {
        return form;
    }

    /**
     * @param form the form to set
     */
    public void setForm(Form form) {
        this.form = form;
    }

}
